﻿
    using System;
    using System.Text;
namespace WCYCReader.Drawing
{
    public static class UnicodeUtils
    {
        private const char A_KANA_LONG_VOW = '\u3095';

        private const char A_LC_LIGATURE = '\u0004';

        private const char A_UC_LIGATURE = '\u0003';

        private const char AELIG_LC = 'æ';

        private const char AELIG_UC = 'Æ';

        private const char E_KANA_LONG_VOW = '\u3098';

        private const char HW_A_KANA_LONG_VOW = '\u0010';

        private const char HW_E_KANA_LONG_VOW = '\u0013';

        private const char HW_I_KANA_LONG_VOW = '\u0011';

        private const char HW_KANA_LONG_VOWEL = '\uFF70';

        private const char HW_O_KANA_LONG_VOW = '\u0014';

        private const char HW_U_KANA_LONG_VOW = '\u0012';

        private const char I_KANA_LONG_VOW = '\u3096';

        private const char KANA_LONG_VOWEL = '\u30FC';

        private const int MAX_LIGATURE_PARTS = 2;

        private const int MAX_UTF16_SIZE = 2;

        private const int MAX_UTF8_SIZE = 6;

        private const char O_KANA_LONG_VOW = '\u309F';

        private const char O_LC_LIGATURE = '\u0002';

        private const char O_UC_LIGATURE = '\u0001';

        private const char OELIG_LC = 'œ';

        private const char OELIG_UC = 'Œ';

        private const char S_LC_LIGATURE = '\u0005';

        private const int SIZE_UNICODE_ALT_WIDTH_SORTORDER = 160;

        private const int SIZE_UNICODE_FULL_WIDTH_LATIN_SORTORDER = 96;

        private const int SIZE_UNICODE_HALF_WIDTH_KANA_SORTORDER = 64;

        private const int SIZE_UNICODE_HANGUL_COMPAJAMO_SORTORDER = 94;

        private const int SIZE_UNICODE_HANGUL_JAMO_SORTORDER = 250;

        private const int SIZE_UNICODE_HANGUL_SYLLABLES_SORTORDER = 11172;

        private const int SIZE_UNICODE_KANA_SORTORDER = 256;

        private const int SIZE_UNICODE_LATIN_SORTORDER = 768;

        private const int START_UNICODE_ALT_WIDTH_SORTORDER = 65280;

        private const int START_UNICODE_FULL_WIDTH_LATIN_SORTORDER = 65280;

        private const int START_UNICODE_HALF_WIDTH_KANA_SORTORDER = 65376;

        private const int START_UNICODE_HANGUL_COMPAJAMO_SORTORDER = 12593;

        private const int START_UNICODE_HANGUL_JAMO_SORTORDER = 4352;

        private const int START_UNICODE_HANGUL_SYLLABLES_SORTORDER = 44032;

        private const int START_UNICODE_KANA_SORTORDER = 12288;

        private const int START_UNICODE_LATIN_SORTORDER = 0;

        private const char SZETLIG_LC = 'ß';

        private const char U_KANA_LONG_VOW = '\u3097';

        public const int UTF16_BE = 65002;

        public const int UTF8 = 65001;

        public const string UTF8_STRING = "UTF-8";

        private const int VOWEL_japanese_half_width_kana_start = 65382;

        private const int VOWEL_japanese_kana_start = 12353;

        public const int WINDOWS1252 = 1252;

        internal readonly static char[] Cannot_end_line;

        internal readonly static char[] Cannot_start_line;

        private static char[][] ligatureTable;

        private static char[][] mobipocketSpecialCodesLigatureTable;

        private readonly static char[] SORTORDER_unicode_alt_width_latin_and_kana;

        private readonly static char[] SORTORDER_unicode_hangul_compajamo;

        private readonly static char[] SORTORDER_unicode_hangul_jamo;

        private readonly static char[] SORTORDER_unicode_japanese_kana;

        private readonly static char[] SORTORDER_unicode_latin;

        private readonly static char[] VOWEL_japanese_half_width_kana;

        private readonly static char[] VOWEL_japanese_kana;

        static UnicodeUtils()
        {
            UnicodeUtils.Cannot_end_line = new char[] { '(', '[', '{', '¡', '«', '\u00B6', '¿', '‘', '‚', '“', '„', '′', '″', '‴', '‹', '\u203F', '⁅', '⁽', '₍', '≦', '≪', '〈', '《', '「', '『', '【', '〔', '〖', '〘', '〚', '〝', '\u302A', '\u302C', '\u3033', '\u3034', '\u309B', '\u30FC', '（', '＜', '［', '｛', '｢' };
            UnicodeUtils.Cannot_start_line = new char[] { '!', ')', ',', '.', ':', ';', '?', ']', '}', '»', '’', '‛', '”', '‟', '‧', '‵', '‶', '‷', '›', '\u2040', '⁆', '⁾', '₎', '≧', '≫', '、', '。', '〉', '》', '」', '』', '】', '〕', '〗', '〙', '〛', '〞', '\u302B', '\u302D', '\u3035', '\u309C', '・', '！', '）', '，', '．', '：', '；', '＞', '？', '］', '｝', '｣' };
            char[][] chrArray = new char[][] { new char[] { 'o', 'e', 'œ' }, new char[] { 'O', 'E', 'Œ' }, new char[] { 'a', 'e', 'æ' }, new char[] { 'A', 'E', 'Æ' }, new char[] { 's', 's', 'ß' } };
            UnicodeUtils.ligatureTable = chrArray;
            char[][] chrArray1 = new char[][] { new char[] { '\u0002', 'e', 'œ' }, new char[] { '\u0001', 'E', 'Œ' }, new char[] { '\u0004', 'e', 'æ' }, new char[] { '\u0003', 'E', 'Æ' }, new char[] { '\u0005', 's', 'ß' } };
            UnicodeUtils.mobipocketSpecialCodesLigatureTable = chrArray1;
            UnicodeUtils.SORTORDER_unicode_alt_width_latin_and_kana = new char[] { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '\0', '\0', '\0', '\0', '\0', '\0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\u3092', '\u3041', '\u3043', '\u3045', '\u3047', '\u3049', '\u3083', '\u3085', '\u3087', '\u3063', '\0', '\u3042', '\u3044', '\u3046', '\u3048', '\u304A', '\u304B', '\u304D', '\u304F', '\u3051', '\u3053', '\u3055', '\u3057', '\u3059', '\u305B', '\u305D', '\u305F', '\u3061', '\u3064', '\u3066', '\u3068', '\u306A', '\u306B', '\u306C', '\u306D', '\u306E', '\u306F', '\u3072', '\u3075', '\u3078', '\u307B', '\u307E', '\u307F', '\u3080', '\u3081', '\u3082', '\u3084', '\u3086', '\u3088', '\u3089', '\u308A', '\u308B', '\u308C', '\u308D', '\u308F', '\u3093', '\0', '\0' };
            UnicodeUtils.SORTORDER_unicode_hangul_compajamo = new char[] { '\uAC00', '\uAE4E', '\uB09C', '\uB0A0', '\uB2F3', '\uB2F5', '\uB2F8', '\uB548', '\uB798', '\uB9E6', '\uB9EC', '\uB9EF', '\uB9F3', '\uB9F8', '\uB9F9', '\uB9FA', '\uB9FE', '\uBC57', '\uBEAA', '\uC0F9', '\uC108', '\uC35F', '\uC5BE', '\uC81C', '\uCA6C', '\uCCBF', '\uCF13', '\uD161', '\uD3AF', '\uD601', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\0', '\uB2EF', '\uB2F0', '\uB2F2', '\uB2F6', '\uB9E7', '\uB9E9', '\uB9F0', '\uB9F5', '\uB9FB', '\uBC4E', '\uBC4F', '\uBC51', '\uBC52', '\uBEA5', '\uBEA7', '\uC0FA', '\uC0FB', '\uC100', '\uC102', '\uC0FF', '\uC0F8', '\uC356', '\uC357', '\uC358', '\uC35B', '\uC5AF', '\uC5BC', '\uC813', '\uC5BE', '\uC811', '\uC812', '\uD5FF', '\uD853', '\uD855', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857' };
            UnicodeUtils.SORTORDER_unicode_hangul_jamo = new char[] { '\uAC00', '\uAE4E', '\uB0A0', '\uB2F8', '\uB548', '\uB798', '\uB9FE', '\uBC57', '\uBEAA', '\uC108', '\uC35F', '\uC5BE', '\uC81C', '\uCA6C', '\uCCBF', '\uCF13', '\uD161', '\uD3AF', '\uD601', '\uB2EE', '\uB2EF', '\uB2F0', '\uB2F1', '\uB546', '\uB9E8', '\uB9EB', '\uB9FA', '\uB9F6', '\uBC4E', '\uBC52', '\uBEA5', '\uBEA6', '\uBEA7', '\uC0F9', '\uC0FA', '\uC0FB', '\uC0FC', '\uC0FD', '\uC0FE', '\uC100', '\uC101', '\uC102', '\uC103', '\uC0FF', '\uC0F8', '\uC356', '\uC357', '\uC358', '\uC359', '\uC35A', '\uC35B', '\uC35C', '\uC5AD', '\uC5AE', '\uC5AF', '\uC5B0', '\uC5B1', '\uC5B2', '\uC5B3', '\uC5B4', '\uC5B7', '\uC5B8', '\uC5B9', '\uC5BA', '\uC5BC', '\uC80C', '\uC80E', '\uC80F', '\uC810', '\uC811', '\uC812', '\uC813', '\uC814', '\uC815', '\uC817', '\uC818', '\uC5BE', '\uCA6A', '\uCCBA', '\uCCBB', '\uCCBC', '\uCCBD', '\uCF0D', '\uCF0E', '\uCF10', '\uCF11', '\uD5FE', '\uD5FF', '\uD853', '\uD855', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\uD857', '\0', '\0', '\0', '\0', '\0', '\uAC00', '\uAE4E', '\uB09C', '\uB0A0', '\uB2F3', '\uB2F5', '\uB2F8', '\uB798', '\uB9E6', '\uB9EC', '\uB9EF', '\uB9F3', '\uB9F8', '\uB9F9', '\uB9FA', '\uB9FE', '\uBC57', '\uC0F9', '\uC108', '\uC35F', '\uC5BE', '\uC81C', '\uCCBF', '\uCF13', '\uD161', '\uD3AF', '\uD601', '\uB09D', '\uB09E', '\uB2EE', '\uB2F0', '\uB2F2', '\uB2F6', '\uB2F4', '\uB546', '\uB796', '\uB9E7', '\uB9E8', '\uB9E9', '\uB9EA', '\uB9EB', '\uB9ED', '\uB9EE', '\uB9F0', '\uB9F1', '\uB9F2', '\uB9F4', '\uB9F5', '\uB9F7', '\uB9FB', '\uBC4C', '\uBC4D', '\uBC4E', '\uBC4F', '\uBC50', '\uBC51', '\uBC53', '\uBC54', '\uBC52', '\uBEA8', '\uC103', '\uC104', '\uC0FF', '\uC356', '\uC358', '\uC359', '\uC35B', '\uC5BC', '\uC80C', '\uC80D', '\uC813', '\uC816', '\uC5BE', '\uC811', '\uC812', '\uD5FE', '\uD5FF', '\uD84F', '\uD850', '\uD851', '\uD852', '\uD855' };
            UnicodeUtils.SORTORDER_unicode_japanese_kana = new char[] { ' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\u3041', '\u3042', '\u3043', '\u3044', '\u3045', '\u3046', '\u3047', '\u3048', '\u3049', '\u304A', '\u304B', '\u304C', '\u304D', '\u304E', '\u304F', '\u3050', '\u3051', '\u3052', '\u3053', '\u3054', '\u3055', '\u3056', '\u3057', '\u3058', '\u3059', '\u305A', '\u305B', '\u305C', '\u305D', '\u305E', '\u305F', '\u3060', '\u3061', '\u3062', '\u3063', '\u3064', '\u3065', '\u3066', '\u3067', '\u3068', '\u3069', '\u306A', '\u306B', '\u306C', '\u306D', '\u306E', '\u306F', '\u3070', '\u3071', '\u3072', '\u3073', '\u3074', '\u3075', '\u3076', '\u3077', '\u3078', '\u3079', '\u307A', '\u307B', '\u307C', '\u307D', '\u307E', '\u307F', '\u3080', '\u3081', '\u3082', '\u3083', '\u3084', '\u3085', '\u3086', '\u3087', '\u3088', '\u3089', '\u308A', '\u308B', '\u308C', '\u308D', '\u308E', '\u308F', '\u3090', '\u3091', '\u3092', '\u3093', '\u3046', '\u3042', '\u3044', '\u3046', '\u3048', '\0', '\0', '\0', '\0', '\0', '\0', '\u304A', '\0', '\u3041', '\u3042', '\u3043', '\u3044', '\u3045', '\u3046', '\u3047', '\u3048', '\u3049', '\u304A', '\u304B', '\u304C', '\u304D', '\u304E', '\u304F', '\u3050', '\u3051', '\u3052', '\u3053', '\u3054', '\u3055', '\u3056', '\u3057', '\u3058', '\u3059', '\u305A', '\u305B', '\u305C', '\u305D', '\u305E', '\u305F', '\u3060', '\u3061', '\u3062', '\u3063', '\u3064', '\u3065', '\u3066', '\u3067', '\u3068', '\u3069', '\u306A', '\u306B', '\u306C', '\u306D', '\u306E', '\u306F', '\u3070', '\u3071', '\u3072', '\u3073', '\u3074', '\u3075', '\u3076', '\u3077', '\u3078', '\u3079', '\u307A', '\u307B', '\u307C', '\u307D', '\u307E', '\u307F', '\u3080', '\u3081', '\u3082', '\u3083', '\u3084', '\u3085', '\u3086', '\u3087', '\u3088', '\u3089', '\u308A', '\u308B', '\u308C', '\u308D', '\u308E', '\u308F', '\u3090', '\u3091', '\u3092', '\u3093', '\u3046', '\u304B', '\u3051', '\u308F', '\u3090', '\u3091', '\u3092', '\0', '\0', '\0', '\0', '\0' };
            UnicodeUtils.SORTORDER_unicode_latin = new char[] { '\0', 'o', 'o', 'a', 'a', 's', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\u3042', '\u3044', '\u3046', '\u3048', '\u304A', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '\0', '\0', '\0', '\0', '\0', '\0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '2', '3', '\0', 'm', '\0', '\0', '\0', '1', '\0', '\0', '\0', '\0', '\0', '\0', 'a', 'a', 'a', 'a', 'a', 'a', '\0', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'd', 'n', 'o', 'o', 'o', 'o', 'o', '\0', 'o', 'u', 'u', 'u', 'u', 'y', 't', '\0', 'a', 'a', 'a', 'a', 'a', 'a', '\0', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'd', 'n', 'o', 'o', 'o', 'o', 'o', '\0', 'o', 'u', 'u', 'u', 'u', 'y', 't', 'y', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'g', 'g', 'g', 'g', 'g', 'g', 'g', 'g', 'h', 'h', 'h', 'h', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', '\0', '\0', 'j', 'j', 'k', 'k', 'k', 'l', 'l', 'l', 'l', 'l', 'l', 'l', 'l', 'l', 'l', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'o', 'o', 'o', 'o', 'o', 'o', '\0', '\0', 'r', 'r', 'r', 'r', 'r', 'r', 's', 's', 's', 's', 's', 's', 's', 's', 't', 't', 't', 't', 't', 't', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'w', 'w', 'y', 'y', 'y', 'z', 'z', 'z', 'z', 'z', 'z', 's', 'b', 'b', 'b', 'b', '\0', '\0', 'o', 'c', 'c', 'd', 'd', 'd', 'd', '\0', 'e', 'e', 'e', 'f', 'f', 'g', 'g', '\0', '\0', 'i', 'k', 'k', 'l', '\0', 'm', 'n', 'n', 'o', 'o', 'o', '\0', '\0', 'p', 'p', 'r', '\0', '\0', '\0', '\0', 't', 't', 't', 't', 'u', 'u', '\0', 'v', 'y', 'y', 'z', 'z', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 'a', 'a', 'i', 'i', 'o', 'o', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'e', 'a', 'a', 'a', 'a', '\0', '\0', 'g', 'g', 'g', 'g', 'k', 'k', 'o', 'o', 'o', 'o', '\0', '\0', 'j', '\0', '\0', '\0', 'g', 'g', '\0', '\0', '\0', '\0', 'a', 'a', 'a', '\0', 'o', 'o', 'a', 'a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', 'r', 'r', 'r', 'r', 'u', 'u', 'u', 'u', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 'a', '\0', '\0', 'b', 'o', 'c', 'd', 'd', 'e', 'e', 'e', '\0', '\0', '\0', '\0', 'j', 'g', 'g', 'g', '\0', '\0', 'h', 'h', 'h', 'i', '\0', 'i', 'l', 'l', 'l', '\0', 'm', 'm', 'm', 'n', 'n', 'n', 'o', '\0', '\0', '\0', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 's', '\0', 'j', '\0', '\0', 't', 't', 'u', '\0', 'v', 'v', 'w', 'y', 'y', 'z', 'z', '\0', '\0', '\0', '\0', '\0', 'c', '\0', 'b', '\0', 'g', 'h', 'j', 'k', 'l', 'q', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' };
            UnicodeUtils.VOWEL_japanese_half_width_kana = new char[] { 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'F', 'J', 'F', '\0', 'B', 'D', 'F', 'H', 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'F', 'J', 'B', 'D', 'F', 'H', 'J', 'B', '\0' };
            UnicodeUtils.VOWEL_japanese_kana = new char[] { 'B', 'B', 'D', 'D', 'F', 'F', 'H', 'H', 'J', 'J', 'B', 'B', 'D', 'D', 'F', 'F', 'H', 'H', 'J', 'J', 'B', 'B', 'D', 'D', 'F', 'F', 'H', 'H', 'J', 'J', 'B', 'B', 'D', 'D', 'F', 'F', 'F', 'H', 'H', 'J', 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'B', 'B', 'D', 'D', 'D', 'F', 'F', 'F', 'H', 'H', 'H', 'J', 'J', 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'B', 'F', 'F', 'J', 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'B', 'D', 'H', 'J', '\0', 'F', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', 'B', 'B', 'D', 'D', 'F', 'F', 'H', 'H', 'J', 'J', 'B', 'B', 'D', 'D', 'F', 'F', 'H', 'H', 'J', 'J', 'B', 'B', 'D', 'D', 'F', 'F', 'H', 'H', 'J', 'J', 'B', 'B', 'D', 'D', 'F', 'F', 'F', 'H', 'H', 'J', 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'B', 'B', 'D', 'D', 'D', 'F', 'F', 'F', 'H', 'H', 'H', 'J', 'J', 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'B', 'F', 'F', 'J', 'J', 'B', 'D', 'F', 'H', 'J', 'B', 'B', 'D', 'H', 'J', '\0', 'F', 'B', 'H', 'B', 'D', 'H', 'J' };
        }

        private static bool canBeTrimmed(char a)
        {
            if (a <= ' ')
            {
                return true;
            }
            if (a <= '\u2000' && a >= '\u200D')
            {
                return true;
            }
            int num = a;
            if (num <= 8239)
            {
                if (num == 160 || num == 8239)
                {
                    return true;
                }
                return false;
            }
            else if (num != 8288 && num != 65279)
            {
                return false;
            }
            return true;
        }

        public static bool cannotEndLine(char a)
        {
            return UnicodeUtils.isInTable(a, UnicodeUtils.Cannot_end_line);
        }

        public static bool cannotStartLine(char a)
        {
            return UnicodeUtils.isInTable(a, UnicodeUtils.Cannot_start_line);
        }

        public static char[] charFromBuffer(sbyte[] data, int offset, int length, int encoding)
        {
            char[] chars = null;
            int num = encoding;
            if (num == 1252)
            {
                return UnicodeWestern.convertToChar(data, offset, length);
            }
            if (num != 65001)
            {
                return null;
            }
            StringBuilder stringBuilder = UnicodeUtils.stringFromUTF8Secure(data, offset, length);
            if (stringBuilder != null)
            {
                chars = new char[stringBuilder.Length];
                for (int i = 0; i < stringBuilder.Length; i++)
                {
                    chars[i] = stringBuilder[i];
                }
            }
            return chars;
        }

        public static string convertFromUnicodeIndexEncoding(sbyte[] src, int beginIndex, int length, char[] mapTable, bool unicode_single_byte)
        {
            int num;
            char longVowelMark;
            if (src == null)
            {
                return null;
            }
            num = (!unicode_single_byte ? length / 2 : length);
            int num1 = 0;
            char[] chrArray = new char[num];
            int num2 = 0;
            while (num2 < length)
            {
                if (!unicode_single_byte)
                {
                    longVowelMark = (char)(((255 & src[beginIndex + num2]) << 8) + (255 & src[beginIndex + num2 + 1]));
                    num2 = num2 + 2;
                }
                else
                {
                    longVowelMark = (char)(255 & src[beginIndex + num2]);
                    num2++;
                }
                if (mapTable != null && longVowelMark < (char)((int)mapTable.Length))
                {
                    longVowelMark = mapTable[longVowelMark];
                }
                longVowelMark = UnicodeUtils.unicodeKanaToLongVowelMark(longVowelMark, true);
                int num3 = num1;
                num1 = num3 + 1;
                chrArray[num3] = longVowelMark;
            }
            char[] chrArray1 = new char[] { default(char), '\0' };
            int num4 = 0;
            int num5 = 1;
            for (int i = 0; i < num1; i++)
            {
                chrArray1[0] = chrArray1[1];
                chrArray1[1] = chrArray[i];
                if (num5 == 0)
                {
                    UnicodeLigatureResult unicodeLigatureResult = UnicodeUtils.unicodeLigature(chrArray1, true);
                    num5 = unicodeLigatureResult.inSize;
                    char item = unicodeLigatureResult[0];
                    int num6 = num4;
                    num4 = num6 + 1;
                    chrArray[num6] = item;
                }
                num5--;
            }
            if (num5 == 0 && num1 >= 1)
            {
                int num7 = num4;
                num4 = num7 + 1;
                chrArray[num7] = chrArray1[1];
            }
            num1 = num4;
            return new string(chrArray, 0, num1);
        }

        public static sbyte[] convertIndexEncodingFromWestern(sbyte[] src, int begin, int length, sbyte[] ligTable, bool toIndexEnc)
        {
            sbyte num;
            sbyte num1;
            sbyte num2;
            sbyte num3;
            sbyte num4;
            if (src == null)
            {
                return null;
            }
            sbyte[] numArray = new sbyte[length << 1];
            int num5 = 0;
            int num6 = (int)ligTable.Length >> 2;
            int num7 = begin + length;
            for (int i = begin; i < num7; i++)
            {
                sbyte num8 = src[i];
                if (i + 1 >= num7)
                {
                    num = 0;
                }
                else
                {
                    num = src[i + 1];
                }
                bool flag = false;
                for (int j = 0; j < num6; j++)
                {
                    int num9 = j << 2;
                    num1 = (!toIndexEnc ? ligTable[num9 + 2] : ligTable[num9]);
                    if (num1 == num8)
                    {
                        if (!toIndexEnc)
                        {
                            num2 = ligTable[num9 + 3];
                            num3 = ligTable[num9];
                            num4 = ligTable[num9 + 1];
                        }
                        else
                        {
                            num2 = ligTable[num9 + 1];
                            num3 = ligTable[num9 + 2];
                            num4 = ligTable[num9 + 3];
                        }
                        if (num2 == 0 || num2 == num)
                        {
                            flag = true;
                            int num10 = num5;
                            num5 = num10 + 1;
                            numArray[num10] = num3;
                            if (num4 != 0)
                            {
                                int num11 = num5;
                                num5 = num11 + 1;
                                numArray[num11] = num4;
                            }
                            if (num2 == num && num != 0)
                            {
                                i++;
                            }
                        }
                    }
                }
                if (!flag)
                {
                    int num12 = num5;
                    num5 = num12 + 1;
                    numArray[num12] = num8;
                }
            }
            sbyte[] numArray1 = new sbyte[num5];
            Buffer.BlockCopy(numArray, 0, numArray1, 0, num5);
            return numArray1;
        }

        public static char[] convertToUnicodeIndexEncoding(string str, bool unicode_single_byte, char[] mapTable)
        {
            bool unicodeSingleByte = false;
            bool flag = false;
            char[] charArray = str.ToCharArray();
            char[] chrArray = new char[(int)charArray.Length * 2];
            int num = 0;
            char chr = '\0';
            char chr1 = '\0';
            for (int i = 0; i < (int)charArray.Length; i++)
            {
                char chr2 = charArray[i];
                if (chr2 > '\0')
                {
                    if (UnicodeUtils.kanaVowel(chr1) != 0)
                    {
                        chr = chr1;
                    }
                    chr1 = chr2;
                    chr1 = UnicodeUtils.kanaFromLongVowelMark(chr1, chr, true);
                    UnicodeLigatureResult unicodeLigatureResult = UnicodeUtils.unicodeUnligature(chr1, true);
                    for (int j = 0; j < unicodeLigatureResult.Length; j++)
                    {
                        unicodeSingleByte = false;
                        char item = unicodeLigatureResult[j];
                        if (mapTable != null)
                        {
                            if (!UnicodeUtils.isOrdered(item) || UnicodeUtils.isHangul(item))
                            {
                                unicodeSingleByte = unicode_single_byte;
                            }
                            else
                            {
                                int num1 = UnicodeUtils.findUnicodeIndexChar(item, mapTable);
                                if (num1 == -1)
                                {
                                    num1 = UnicodeUtils.findUnicodeIndexChar(UnicodeUtils.sortOrder(item), mapTable);
                                    unicodeSingleByte = num1 == -1;
                                }
                                item = (char)num1;
                            }
                        }
                        if (unicodeSingleByte)
                        {
                            item = '\0';
                            flag = true;
                        }
                        chrArray[num] = item;
                        num++;
                    }
                }
            }
            if (flag)
            {
                return null;
            }
            char[] chrArray1 = new char[num];
            Array.Copy(chrArray, 0, chrArray1, 0, num);
            return chrArray1;
        }

        private static int findUnicodeIndexChar(char a, char[] charTable)
        {
            for (int i = 0; i < (int)charTable.Length; i++)
            {
                if (charTable[i] == a)
                {
                    return i;
                }
            }
            return -1;
        }

        private static bool isHangul(char a)
        {
            if (a < '\uAC00')
            {
                return false;
            }
            return a <= '\uD7AF';
        }

        private static bool isIdeograph(char a)
        {
            if (a >= '\u3400' && a <= '\u9FAF' || a >= '\uF900' && a <= '\uFAFF')
            {
                return true;
            }
            if (a < '\u2E80')
            {
                return false;
            }
            return a <= '\u2FDF';
        }

        public static bool isIdeographic(char a)
        {
            if (UnicodeUtils.isIdeograph(a) || a >= '\u3000' && a <= '\u32FF' || a >= '\u1100' && a <= '\u11FF' || a >= '\uAC00' && a <= '\uD7AF')
            {
                return true;
            }
            if (a < '\uFF00')
            {
                return false;
            }
            return a <= '\uFFEE';
        }

        private static bool isInTable(char a, char[] table)
        {
            int num = 0;
            int length = (int)table.Length - 1;
            if (num >= length)
            {
                return false;
            }
            while (true)
            {
                int num1 = (num + length) / 2;
                if (table[num1] == a)
                {
                    return true;
                }
                if (table[num1 + 1] == a)
                {
                    return true;
                }
                if (num1 == num)
                {
                    break;
                }
                if (a >= table[num1])
                {
                    num = num1;
                }
                else
                {
                    length = num1;
                }
            }
            return false;
        }

        public static bool isOrdered(char a)
        {
            if (a >= '\0' && a < '\u0300' || a >= '\u3000' && a < '\u3100' || a >= '\uFF00' && a < '\uFFA0' || a >= '\u1100' && a < '\u11FA' || a >= '\u3131' && a < '\u318F' || a >= '\uAC00' && a < '\uD7A4' || a >= '\u2000' && a <= '\u206F' || a >= '←' && a <= '\u23FF' || a >= '\u2500' && a <= '⟿')
            {
                return true;
            }
            if (a < '⤀')
            {
                return false;
            }
            return a <= '\u2BFF';
        }

        private static char kanaFromLongVowelMark(char a, char prev_a, bool mobipocket_special_codes)
        {
            char chr = a;
            if (a != '\u30FC' && a != '\uFF70')
            {
                return chr;
            }
            char chr1 = UnicodeUtils.kanaVowel(prev_a);
            if (chr1 == 0)
            {
                return chr;
            }
            bool flag = a == '\uFF70';
            if (!mobipocket_special_codes)
            {
                return chr1;
            }
            switch (chr1)
            {
                case '\u3042':
                    {
                        if (!flag)
                        {
                            return '\u3095';
                        }
                        return '\u0010';
                    }
                case '\u3043':
                case '\u3045':
                case '\u3047':
                case '\u3049':
                    {
                        return chr;
                    }
                case '\u3044':
                    {
                        if (!flag)
                        {
                            return '\u3096';
                        }
                        return '\u0011';
                    }
                case '\u3046':
                    {
                        if (!flag)
                        {
                            return '\u3097';
                        }
                        return '\u0012';
                    }
                case '\u3048':
                    {
                        if (!flag)
                        {
                            return '\u3098';
                        }
                        return '\u0013';
                    }
                case '\u304A':
                    {
                        if (!flag)
                        {
                            return '\u309F';
                        }
                        return '\u0014';
                    }
            }
            return chr;
        }

        private static char kanaVowel(char a)
        {
            char vOWELJapaneseKana;
            if (a < '\u3041' || a >= (char)(12353 + (int)UnicodeUtils.VOWEL_japanese_kana.Length))
            {
                vOWELJapaneseKana = (a < '\uFF66' || a >= (char)(65382 + (int)UnicodeUtils.VOWEL_japanese_half_width_kana.Length) ? '\0' : UnicodeUtils.VOWEL_japanese_half_width_kana[a - 65382]);
            }
            else
            {
                vOWELJapaneseKana = UnicodeUtils.VOWEL_japanese_kana[a - 12353];
            }
            if (vOWELJapaneseKana > '\0')
            {
                vOWELJapaneseKana = (char)(vOWELJapaneseKana + 12288);
            }
            return vOWELJapaneseKana;
        }

        public static char sortOrder(char a)
        {
            if (a >= '\0' && a < '\u0300')
            {
                return UnicodeUtils.SORTORDER_unicode_latin[a];
            }
            if (a >= '\u3000' && a < '\u3100')
            {
                return UnicodeUtils.SORTORDER_unicode_japanese_kana[a - 12288];
            }
            if (a >= '\uFF00' && a < '\uFFA0')
            {
                return UnicodeUtils.SORTORDER_unicode_alt_width_latin_and_kana[a - 65280];
            }
            if (a >= '\u1100' && a < '\u11FA')
            {
                return UnicodeUtils.SORTORDER_unicode_hangul_jamo[a - 4352];
            }
            if (a < '\u3131' || a >= '\u318F')
            {
                return '\0';
            }
            return UnicodeUtils.SORTORDER_unicode_hangul_compajamo[a - 12593];
        }

        public static string stringFromEncoding(sbyte[] data, int offset, int length, int encoding)
        {
            int num = encoding;
            if (num == 1252)
            {
                return UnicodeUtils.stringFromWestern(data, offset, length);
            }
            switch (num)
            {
                case 65001:
                    {
                        StringBuilder stringBuilder = UnicodeUtils.stringFromUTF8Secure(data, offset, length);
                        if (stringBuilder == null)
                        {
                            return null;
                        }
                        return stringBuilder.ToString();
                    }
                case 65002:
                    {
                        return UnicodeUtils.stringFromUTF16BE(data, offset, length);
                    }
            }
            return null;
        }

        public static string stringFromUTF16BE(sbyte[] data, int offset, int length)
        {
            int num = length >> 1;
            char[] chrArray = new char[num];
            for (int i = 0; i < num; i++)
            {
                chrArray[i] = (char)((data[offset] << 8) + (data[offset + 1] & 255));
                offset = offset + 2;
            }
            return new string(chrArray);
        }

        public static StringBuilder stringFromUTF8Secure(sbyte[] src, int offset, int length)
        {
            int num;
            if (src == null || 0 >= (int)src.Length)
            {
                return null;
            }
            StringBuilder stringBuilder = new StringBuilder(length);
            int num1 = offset + length;
            int num2 = offset;
            while (num2 < num1)
            {
                if ((src[num2] & 128) == 0 || (src[num2] & 192) == 128)
                {
                    int num3 = num2;
                    num2 = num3 + 1;
                    num = src[num3] & 255;
                }
                else if ((src[num2] & 224) == 192)
                {
                    int num4 = num2;
                    num2 = num4 + 1;
                    int num5 = num2;
                    num2 = num5 + 1;
                    num = (src[num4] & 31) << 6 | src[num5] & 63;
                }
                else if ((src[num2] & 240) != 224)
                {
                    int num6 = num2;
                    num2 = num6 + 1;
                    int num7 = num2;
                    num2 = num7 + 1;
                    int num8 = num2;
                    num2 = num8 + 1;
                    int num9 = num2;
                    num2 = num9 + 1;
                    num = (src[num6] & 7) << 18 | (src[num7] & 63) << 12 | (src[num8] & 63) << 6 | src[num9] & 63;
                }
                else
                {
                    int num10 = num2;
                    num2 = num10 + 1;
                    int num11 = num2;
                    num2 = num11 + 1;
                    int num12 = num2;
                    num2 = num12 + 1;
                    num = (src[num10] & 15) << 12 | (src[num11] & 63) << 6 | src[num12] & 63;
                }
                if (num < 65536)
                {
                    stringBuilder.Append((char)num);
                }
                else
                {
                    stringBuilder.Append((ushort)(num >> 10) + 55232);
                    stringBuilder.Append((ushort)(num & 1023) + 56320);
                }
            }
            return stringBuilder;
        }

        public static string stringFromWestern(sbyte[] data, int offset, int length)
        {
            return new string(UnicodeWestern.convertToChar(data, offset, length));
        }

        public static sbyte[] stringToEncoding(string str, int encoding)
        {
            int num = encoding;
            if (num == 1252)
            {
                return UnicodeUtils.stringToWestern(str);
            }
            switch (num)
            {
                case 65001:
                    {
                        return UnicodeUtils.stringToUTF8(str);
                    }
                case 65002:
                    {
                        return UnicodeUtils.stringToUTF16BE(str);
                    }
            }
            return null;
        }

        public static sbyte[] stringToUTF16BE(string str)
        {
            char[] charArray = str.ToCharArray();
            sbyte[] numArray = new sbyte[(int)charArray.Length * 2];
            int num = 0;
            for (int i = 0; i < (int)charArray.Length; i++)
            {
                int num1 = charArray[i];
                int num2 = num;
                num = num2 + 1;
                numArray[num2] = (sbyte)(num1 >> 8 & 255);
                int num3 = num;
                num = num3 + 1;
                numArray[num3] = (sbyte)(num1 & 255);
            }
            return numArray;
        }

        public static sbyte[] stringToUTF8(string str)
        {
            sbyte[] sbytes;
            try
            {
                //bytes = (sbyte[])Encoding.UTF8.GetBytes(str);
                byte[] bytes = Encoding.UTF8.GetBytes(str);
                sbytes = new sbyte[bytes.Length];
                for (int i = 0; i < bytes.Length; i++)
                {
                    if (bytes[i] > 127)
                        sbytes[i] = (sbyte)(bytes[i] - 256);
                    else
                        sbytes[i] = (sbyte)bytes[i];
                }
            }
            catch
            {
                sbytes = null;
            }
            return sbytes;
        }

        public static sbyte[] stringToWestern(string unicodeString)
        {
            return UnicodeWestern.convert(unicodeString);
        }

        public static string trim(string str)
        {
            int length = str.Length;
            int num = 0;
            while (num < length && UnicodeUtils.canBeTrimmed(str[num]))
            {
                num++;
            }
            str = str.Substring(num);
            num = str.Length - 1;
            while (num >= 0 && UnicodeUtils.canBeTrimmed(str[num]))
            {
                num--;
            }
            return str.Substring(0, num + 1);
        }

        private static char unicodeKanaToLongVowelMark(char a, bool mobipocket_special_codes)
        {
            char chr = a;
            if (mobipocket_special_codes)
            {
                char chr1 = a;
                switch (chr1)
                {
                    case '\u0010':
                    case '\u0011':
                    case '\u0012':
                    case '\u0013':
                    case '\u0014':
                        {
                            return '\uFF70';
                        }
                    default:
                        {
                            switch (chr1)
                            {
                                case '\u3095':
                                case '\u3096':
                                case '\u3097':
                                case '\u3098':
                                    {
                                        return '\u30FC';
                                    }
                                default:
                                    {
                                        if (chr1 == '\u309F')
                                        {
                                            return '\u30FC';
                                        }
                                        break;
                                    }
                            }
                            break;
                        }
                }
            }
            return chr;
        }

        private static UnicodeLigatureResult unicodeLigature(char[] ins0, bool mobipocket_special_codes)
        {
            if (mobipocket_special_codes)
            {
                return UnicodeUtils.unicodeLigatureWithTable(ins0, UnicodeUtils.mobipocketSpecialCodesLigatureTable);
            }
            return UnicodeUtils.unicodeLigatureWithTable(ins0, UnicodeUtils.ligatureTable);
        }

        private static UnicodeLigatureResult unicodeLigatureWithTable(char[] ins0, char[][] table)
        {
            for (int i = 0; i < (int)table.Length; i++)
            {
                if (ins0[0] == table[i][0] && ins0[1] == table[i][1])
                {
                    return new UnicodeLigatureResult(2, table[i][2]);
                }
            }
            return new UnicodeLigatureResult(1, ins0[0]);
        }

        private static UnicodeLigatureResult unicodeUnligature(char ins0, bool mobipocket_special_codes)
        {
            if (mobipocket_special_codes)
            {
                return UnicodeUtils.unicodeUnligatureWithTable(ins0, UnicodeUtils.mobipocketSpecialCodesLigatureTable);
            }
            return UnicodeUtils.unicodeUnligatureWithTable(ins0, UnicodeUtils.ligatureTable);
        }

        private static UnicodeLigatureResult unicodeUnligatureWithTable(char ins0, char[][] table)
        {
            for (int i = 0; i < (int)table.Length; i++)
            {
                if (ins0 == table[i][2])
                {
                    return new UnicodeLigatureResult(1, table[i][0], table[i][1]);
                }
            }
            return new UnicodeLigatureResult(1, ins0);
        }
    }
}

